package com.neusoft.liduan.d0915;

import java.awt.Graphics;
import java.util.Arrays;

public class ShapeArray {
	private Shape[] array;
	private int index;
	
	public ShapeArray() {
		array = new Shape[10];
	}
	
	public void push(Shape s) {
		getShapeIndex();
		if(index == array.length - 1) {
//			Shape[] newArray = new Shape[index + 10];
			array = Arrays.copyOf(array, index + 10);
		}else {
			array[index] = s;
		}
	}
	
	public int getShapeIndex() {
		int len = array.length;
		if(len == 0) {
			return 0;
		}
		for(int i = 0; i < array.length; i++) {
			if(array[i] == null) {
				index = i;
				break;
			}
		}
		
		return index;
	}
	
	public Shape[] getArray() {
		return array;
	}
	
	public void draw(Graphics g) {
		for(int i = 0; i < array.length; i++) {
			if(array[i] == null) {
				break;
			}
			array[i].draw(g);
		}
	}
}
